package api_sys

import (
	"github.com/gin-gonic/gin"
	"strconv"
	"wrblog-api-go/app/common/token"
	"wrblog-api-go/app/model/model_sys"
	"wrblog-api-go/app/service/service_sys"
	"wrblog-api-go/pkg/request"
	"wrblog-api-go/pkg/result"
	"wrblog-api-go/pkg/status"
)

// @Tags  System - 岗位管理
// @Summary  获取岗位列表
// @Accept json
// @Produce json
// @Param Authorization header string true "Authorization"
// @Param sysPost query model_sys.SelectSysPost true "sysPost"
// @Success 200 {object} result.Result "OK"
// @Router /sysPost/page [get]
func ApiSysPostPageList(c *gin.Context) {
	raw, _ := c.Get(request.BindObj)
	sysPost := raw.(model_sys.SelectSysPost)
	result.PageRes(service_sys.GetSysPostPageList(sysPost)).Json(c)
}

// @Tags  System - 岗位管理
// @Summary  获取岗位详情
// @Accept json
// @Produce json
// @Param Authorization header string true "Authorization"
// @Param postId path int true "postId"
// @Success 200 {object} result.Result "OK"
// @Router /sysPost/{postId} [get]
func ApiSysPostById(c *gin.Context) {
	postId, err := strconv.Atoi(c.Param("postId"))
	if err != nil {
		result.Wrap(status.BadRequest, "参数读取失败").Json(c)
	} else {
		result.Res(service_sys.GetSysPostById(postId)).Json(c)
	}
}

// @Tags  System - 岗位管理
// @Summary  添加岗位
// @Accept json
// @Produce json
// @Param Authorization header string true "Authorization"
// @Param sysPost body model_sys.SysPost true "sysPost"
// @Success 200 {object} result.Result "OK"
// @Router /sysPost/add [post]
func ApiAddSysPost(c *gin.Context) {
	raw, _ := c.Get(request.BindObj)
	sysPost := raw.(model_sys.SysPostPo)
	sysPost.CreateBy = token.GetUk(c)
	result.Res(service_sys.AddSysPost(sysPost)).Json(c)
}

// @Tags  System - 岗位管理
// @Summary  修改岗位
// @Accept json
// @Produce json
// @Param Authorization header string true "Authorization"
// @Param sysPost body model_sys.SysPost true "sysPost"
// @Success 200 {object} result.Result "OK"
// @Router /sysPost/edit [put]
func ApiEditSysPost(c *gin.Context) {
	raw, _ := c.Get(request.BindObj)
	sysPost := raw.(model_sys.SysPostPo)
	sysPost.UpdateBy = token.GetUk(c)
	result.Res(service_sys.EditSysPost(sysPost)).Json(c)
}

// @Tags  System - 岗位管理
// @Summary  删除岗位[逻辑删除]
// @Accept json
// @Produce json
// @Param Authorization header string true "Authorization"
// @Param postIds query string true "postIds"
// @Success 200 {object} result.Result "OK"
// @Router /sysPost/removes [delete]
func ApiRemoveSysPost(c *gin.Context) {
	postIds := c.Query("postIds")
	result.Res(service_sys.RemoveSysPost(postIds, token.GetUk(c))).Json(c)
}
